package com.chenju.invokechainservice.utils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FunnyClassUtils {
    public static Class<?> loadClassFromFile(String filePath){
        Path path = Paths.get(filePath);
        try {
            byte[] classBytes = Files.readAllBytes(path);
            Class<?> clazz = new CustomClassLoader().defineClass(classBytes);
            return clazz;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

class CustomClassLoader extends ClassLoader {
    public Class<?> defineClass(byte[] data) {
        return defineClass(null, data, 0, data.length);
    }
}
